﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace lumo.display.object2D
{
    /// <summary>
    /// BoxOverlay Class
    /// </summary>
    public class BoxOverlay : IObject2D, IColorable, IPositionable2D, IOriginable2D, IRotationable2D
    {

    #region Instance

        /// <summary> 
        /// Width of the box
        /// </summary>
        public float? Width = null;

        /// <summary> 
        /// Height of the box
        /// </summary>
        public float? Height = null;

        /// <summary>
        /// Texture of the object
        /// </summary>
        private Texture2D _Texture = null;

        /// <summary>
        /// BoxOverlay Empty constructor.
        /// </summary>
        /// <param name="Game">The game class</param>
        public BoxOverlay(lumo.LumoComponent Game) 
        {
            /* Create the texture */
            _Texture = new Texture2D(Game.GraphicsDevice, 1, 1);
            _Texture.SetData(new Color[] { Color.White });
        }

        /// <summary>
        /// BoxOverlay Empty constructor.
        /// </summary>
        /// <param name="Game">The game class</param>
        /// <param name="Width">Width of the box or null</param>
        /// <param name="Height">Height of the box or null</param>
        public BoxOverlay(lumo.LumoComponent Game, float? Width, float? Height)
        {
            /* Create the texture */
            _Texture = new Texture2D(Game.GraphicsDevice, 1, 1);
            _Texture.SetData(new Color[] { Color.White });

            /* Set the size. */
            this.Width  = Width;
            this.Height = Height;
        }

    #endregion

    #region Interface Implementation

        #region IObject2D

        /// <summary>
        /// Draw implementaion of IObject2D
        /// </summary>
        /// <param name="spriteBatch">The spritebatch object</param>
        public void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            if (_Visible && (_Texture != null))
            {
                Vector2 Size = new Vector2(spriteBatch.GraphicsDevice.Viewport.Width, spriteBatch.GraphicsDevice.Viewport.Height);
                if (Width.HasValue)
                    Size.X = Width.Value;
                if (Height.HasValue)
                    Size.Y = Height.Value;
                spriteBatch.Draw(_Texture, _Position, null, _Color, _Radians, _Origin, Size, SpriteEffects.None, 0f);
            }
        }

        /// <summary>Private draw order float.</summary>
        private float _DrawOrder = 0f;
        /// <summary>
        /// Simple implementation of draw order.
        /// </summary>
        public float DrawOrder { get { return _DrawOrder; } set { _DrawOrder = value; } }

        /// <summary>Private visible variable.</summary>
        private bool _Visible = true;        /// <summary>
        /// Simple implementation of Visible.
        /// </summary>
        public bool Visible { get { return _Visible; } set { _Visible = value; } }

        #endregion

        #region IColorable

        /// <summary> 
        /// Colormask 
        /// </summary>
        private Color _Color = Color.White;
        /// <summary>
        /// Implemetaion of Color. IColorable
        /// </summary>
        public Color Color { get { return _Color; } set { _Color = value; } }
        /// <summary>
        /// Implemetaion of ColorR. IColorable
        /// </summary>
        public byte ColorR { get { return _Color.R; } set { _Color.R = value; } }
        /// <summary>
        /// Implemetaion of ColorG. IColorable
        /// </summary>
        public byte ColorG { get { return _Color.G; } set { _Color.G = value; } }
        /// <summary>
        /// Implemetaion of ColorB. IColorable
        /// </summary>
        public byte ColorB { get { return _Color.B; } set { _Color.B = value; } }
        /// <summary>
        /// Implemetaion of ColorA. IColorable
        /// </summary>
        public byte ColorA { get { return _Color.A; } set { _Color.A = value; } }

        #endregion

        #region IPositionable2D

        /// <summary> 
        /// Coordinates where the object is drawn 
        /// </summary>
        private Vector2 _Position = Vector2.Zero;
        /// <summary>
        /// Implementation of Position. IPositionable2D.
        /// </summary>
        public Vector2 Position { get { return _Position; } set { _Position = value; } }
        /// <summary>
        /// Implementation of X. IPositionable2D.
        /// </summary>
        public float X { get { return _Position.X; } set { _Position.X = value; } }
        /// <summary>
        /// Implementation of Y. IPositionable2D.
        /// </summary>
        public float Y { get { return _Position.Y; } set { _Position.Y = value; } }

        #endregion

        #region IOriginable2D

        /// <summary>
        /// Size of obejct.
        /// </summary>
        public Vector2 Size { get { return new Vector2(Width.Value, Height.Value); } }
        /// <summary> 
        /// Pivot point 
        /// </summary>
        private Vector2 _Origin = Vector2.Zero;
        /// <summary>
        /// Implemetation of Origin. IOriginable2D.
        /// </summary>
        public Vector2 Origin { get { return _Origin; } set { _Origin = value; } }
        /// <summary>
        /// Implementation of OX. IOriginable2D.
        /// </summary>
        public float OX { get { return _Origin.X; } set { _Origin.X = value; } }
        /// <summary>
        /// Implementation of OY. IOriginable2D.
        /// </summary>
        public float OY { get { return _Origin.Y; } set { _Origin.Y = value; } }

        #endregion

        #region IRotationable2D

        /// <summary> 
        /// Angle in radians 
        /// </summary>
        private float _Radians = 0f;
        /// <summary>
        /// Implementation of Radians. IRotationable2D
        /// </summary>
        public float Radians { get { return _Radians; } set { _Radians = value; } }
        /// <summary>
        /// Implementation of Degrees. IRotationable2D
        /// </summary>
        public float Degrees { get { return MathHelper.ToDegrees(_Radians); } set { _Radians = MathHelper.ToRadians(value); } }

        #endregion

    #endregion

    }
}
